﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
using Topshelf.Nancy;

namespace WinServicesTest
{
	class Program
	{
		static void Main(string[] args)
		{
			var host=HostFactory.New(x=> {
				x.Service<NancyService>(s =>
				{
					s.ConstructUsing(settings => new NancyService());
					s.WhenStarted(service => service.Start());
					s.WhenStopped(service=>service.Stop());
					s.WithNancyEndpoint(x, c =>
					{
						c.AddHost(port: 8088);
						c.CreateUrlReservationsOnInstall();
						c.OpenFirewallPortsOnInstall(firewallRuleName: "topshelf.nancy.sampleservice");
					});
				});
				x.StartAutomatically();
				x.RunAsLocalSystem();
				x.SetDescription("Sample Topshelf Host");    
				x.SetDisplayName("Topshelf");                       
				x.SetServiceName("Topshelf");
			});
			host.Run();
		}
	}
}
